//
//  QDBookDoctorNormalCell.m
//  simulateQuickDoctor
//
//  Created by 梁家伟 on 17/3/23.
//  Copyright © 2017年 PipiXia. All rights reserved.
//

#import "QDBookDoctorNormalCell.h"

@interface QDBookDoctorNormalCell ()

@property(nonatomic,weak)UILabel* label;

@end

@implementation QDBookDoctorNormalCell{
    NSMutableArray<UILabel*>* _labelArr;
}

- (void)setupUI{
    
    CGFloat margin = 8;
    
    //切圆角
    self.layer.cornerRadius=10;
    self.layer.masksToBounds = YES;
    
    UILabel* label = [UILabel cz_labelWithText:@"请选择疾病类型:" fontSize:18 color:PPColor];
    label.numberOfLines = 1;
    _label = label;
    [self.contentView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(margin);
        make.right.equalTo(self.contentView).offset(-margin*3);
        make.centerY.equalTo(self.contentView);
    }];
    
    
    self.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"position-right"]];
    
}

- (void)setDataDict:(NSDictionary *)dataDict{
    
    _dataDict = dataDict;
    
    _label.text = _dataDict[@"title"];
    
}

- (void)setComplicationsData:(NSArray<QDComplicationModel*>*)complicationsData{
    
    _complicationsData = complicationsData;
    
    [_label removeFromSuperview];
    self.accessoryView = nil;
    
    _labelArr = [NSMutableArray array];
    
    [_complicationsData enumerateObjectsUsingBlock:^(QDComplicationModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        
        
        UILabel* comLabel = [UILabel cz_labelWithText:obj.complication_name fontSize:13 color:[UIColor whiteColor]];
        comLabel.numberOfLines = 1;
        comLabel.backgroundColor = PPColor;
        comLabel.layer.cornerRadius = 5;
        comLabel.layer.masksToBounds = YES;
        comLabel.textAlignment = NSTextAlignmentCenter;
        
        [self.contentView addSubview:comLabel];
        
        CGFloat margin = 8;
        
        CGFloat width = (self.bounds.size.width - (7 * margin)) / 6;
        
        if(idx == 0){
            
            [comLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView);
                make.left.equalTo(self.contentView).offset(8);
                make.width.offset(width);
                make.height.offset(20);
            }];
        }else{
            UILabel* lastLabel = _labelArr.lastObject;
            [comLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView);
                make.left.equalTo(lastLabel.mas_right).offset(8);
                make.width.offset(width);
                make.height.offset(20);
            }];
        }
        [_labelArr addObject:comLabel];
    }];

}

- (void)resetCell{
    
    for (UILabel* comLabel in _labelArr) {
        [comLabel removeFromSuperview];
    }
    
    [_labelArr removeAllObjects];
}

@end
